import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 实现Callable线程方法
 */
public class CallableDemo {
    public static void main(String[] args) {
        // 执行的任务
        MyCall myCall = new MyCall();
        // 管理执行的结果
        FutureTask<Integer> ft = new FutureTask<>(myCall);
        Thread t = new Thread(ft);
        t.start();

        try {
            System.out.println(ft.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }

    private static class MyCall implements Callable<Integer>{
        @Override
        public Integer call() throws Exception {
            int s = 0;
            for(int i = 0; i < 100; i++){
                s ++;
            }
            return s;
        }
    }
}
